﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using PromoOffersCrawler.Crawler.Data;

namespace PromoOffersCrawler.Web.Controllers
{
    public class KnowedgeController : Controller
    {
        private Entities db = new Entities();

        //
        // GET: /Knowedge/

        public ActionResult Index()
        {
            var websitekknowledges = db.WebSiteKknowledges.Include(w => w.WebSite);
            return View(websitekknowledges.ToList());
        }

        //
        // GET: /Knowedge/Details/5

        public ActionResult Details(int id = 0)
        {
            WebSiteKknowledge websitekknowledge = db.WebSiteKknowledges.Find(id);
            if (websitekknowledge == null)
            {
                return HttpNotFound();
            }
            return View(websitekknowledge);
        }

        //
        // GET: /Knowedge/Create

        public ActionResult Create()
        {
            ViewBag.WebSiteID = new SelectList(db.WebSites, "ID", "Name");
            return View();
        }

        //
        // POST: /Knowedge/Create

        [HttpPost]
        [ValidateInput(false)]
        public ActionResult Create(WebSiteKknowledge websitekknowledge)
        {
            if (ModelState.IsValid)
            {
                db.WebSiteKknowledges.Add(websitekknowledge);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.WebSiteID = new SelectList(db.WebSites, "ID", "Name", websitekknowledge.WebSiteID);
            return View(websitekknowledge);
        }

        //
        // GET: /Knowedge/Edit/5

        public ActionResult Edit(int id = 0)
        {
            WebSiteKknowledge websitekknowledge = db.WebSiteKknowledges.Find(id);
            if (websitekknowledge == null)
            {
                return HttpNotFound();
            }
            ViewBag.WebSiteID = new SelectList(db.WebSites, "ID", "Name", websitekknowledge.WebSiteID);
            return View(websitekknowledge);
        }

        //
        // POST: /Knowedge/Edit/5

        [HttpPost]
        public ActionResult Edit(WebSiteKknowledge websitekknowledge)
        {
            if (ModelState.IsValid)
            {
                db.Entry(websitekknowledge).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            ViewBag.WebSiteID = new SelectList(db.WebSites, "ID", "Name", websitekknowledge.WebSiteID);
            return View(websitekknowledge);
        }

        //
        // GET: /Knowedge/Delete/5

        public ActionResult Delete(int id = 0)
        {
            WebSiteKknowledge websitekknowledge = db.WebSiteKknowledges.Find(id);
            if (websitekknowledge == null)
            {
                return HttpNotFound();
            }
            return View(websitekknowledge);
        }

        //
        // POST: /Knowedge/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {
            WebSiteKknowledge websitekknowledge = db.WebSiteKknowledges.Find(id);
            db.WebSiteKknowledges.Remove(websitekknowledge);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}